package com.example.chatweb.controller;

import com.example.chatweb.dto.BigBaseSearchDTO;
import com.example.chatweb.entity.BigBase;
import com.example.chatweb.service.BigBaseService;
import com.example.chatweb.utils.R;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.format.annotation.DateTimeFormat;
import org.springframework.web.bind.annotation.*;

import java.math.BigInteger;
import java.sql.Date;
import java.util.List;

@RestController
public class BigBaseController {
    @Autowired
    private BigBaseService bigBaseService;

    //查询大库中所有Pdf信息
    @PostMapping("/selectAllPdfs")
    public R getAllPdfs() {
        List<BigBase> pdfs = bigBaseService.list(null);
        return R.ok("查询成功", pdfs);
    }
    //根据pdfId查询Pdf信息
    @PostMapping("/selectPdfBypdfId")
    public R getPdfById(@RequestBody BigInteger pdfId) {
        BigBase pdf = bigBaseService.getById(pdfId);
        if (pdf == null) {
            return R.failure("未找到对应的PDF");
        }
        return R.ok("查询成功", pdf);
    }
    //批量插入
    @PostMapping("/batchInsertPdfs")
    public R batchInsertPdfs(@RequestBody List<BigBase> pdfs) {
        boolean i=bigBaseService.saveBatch(pdfs);
        if(i){
            return R.ok("批量插入成功");
        }else{
            return R.failure("批量插入失败");
        }
    }
    //批量删除
    @PostMapping("/batchDeletePdfs")
    public R batchDeletePdfs(@RequestBody List<BigInteger> pdfIds) {
        boolean i = bigBaseService.removeByIds(pdfIds);
        if (i) {
            return R.ok("批量删除成功");
        } else {
            return R.failure("批量删除失败");
        }
    }
    //批量更新
    @PostMapping("/batchUpdatePdfs")
    public R batchUpdatePdfs(@RequestBody List<BigBase> pdfs) {
        boolean i = bigBaseService.updateBatchById(pdfs);
        if (i) {
            return R.ok("批量更新成功");
        } else {
            return R.failure("批量更新失败");
        }
    }
    //按照给定的元信息查询一批PDF
    @PostMapping("/search-bigbase")
    public List<BigBase> searchPdfs(@RequestBody BigBaseSearchDTO searchDTO) {

        List<BigBase> pdfList = bigBaseService.findPdfsByConditions(searchDTO);
        // 返回查询结果
        return pdfList;
    }
}
